<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Android日常细节记录 | yangchaojiang</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
    <meta name="keywords" content="yangjiang,yangjiang Blog" />
  
  <meta name="description" content="本人日常开发中总结一些细节记录。">
<meta name="keywords" content="Android,Kotlin,java">
<meta property="og:type" content="article">
<meta property="og:title" content="Android日常细节记录">
<meta property="og:url" content="http://yangchaojiang.cn/2018/03/10/record-blog/index.html">
<meta property="og:site_name" content="yangchaojiang">
<meta property="og:description" content="本人日常开发中总结一些细节记录。">
<meta property="og:updated_time" content="2018-03-10T11:32:14.505Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android日常细节记录">
<meta name="twitter:description" content="本人日常开发中总结一些细节记录。">
  
  
    <link rel="icon" href="/favicon.ico">
  
  <link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css">
  <script src="/js/pace.min.js"></script>
  

  
  

</head>

<body>
  <div id="container">
      <header id="header">
    <div id="banner"></div>
    <div id="header-outer">
        <div id="header-menu" class="header-menu-pos animated">
            <div class="header-menu-container">
                <a href="/" class="left">
                    <span class="site-title">杨 江</span>
                </a>
                <nav id="header-menu-nav" class="right">
                    
                    <a target="_blank" href="//yanganan.cn">
                        <i class="fa fa-home"></i>
                        <span>Home</span>
                    </a>
                    
                    <a  href="/archives">
                        <i class="fa fa-archive"></i>
                        <span>Archives</span>
                    </a>
                    
                    <a target="_blank" href="http://www.yanganan.cn/server/about/aboutme.html">
                        <i class="fa fa-user"></i>
                        <span>About</span>
                    </a>
                    
                </nav>
                <a class="mobile-header-menu-button">
                    <i class="fa fa-bars"></i>
                </a>
            </div>
        </div>
        <div id="header-row">
            <div id="logo">
                <a href="/">
                    <img src="/images/logo.png" alt="logo">
                </a>
            </div>
            <div class="header-info">
                <div id="header-title">
                    
                    <h2>
                        杨 江
                    </h2>
                    
                </div>
                <div id="header-description">
                    
                    <h3>
                        海迷、爱运动、爱交友、爱旅行、喜欢接触新鲜事物、迎接新的挑战，更爱游离于错综复杂的编码与逻辑中
                    </h3>
                    
                </div>
            </div>
            <nav class="header-nav">
                <div class="social">
                    
                        <a title="Home" target="_blank" href="//yangchaojiang.cn">
                            <i class="fa fa-home fa-2x"></i></a>
                    
                        <a title="Github" target="_blank" href="//github.com/yangchaojiang">
                            <i class="fa fa-github fa-2x"></i></a>
                    
                        <a title="Weibo" target="_blank" href="//weibo.com/u/5114674051?topnav=1&wvr=6&topsug=1&is_all=1">
                            <i class="fa fa-weibo fa-2x"></i></a>
                    
                        <a title="Mail" target="_blank" href="mailto:yangchaojiang@outlook.com">
                            <i class="fa fa-envelope-o fa-2x"></i></a>
                    
                        <a title="qq" target="_blank" href="//wpa.qq.com/msgrd?v=3&uin=1007181167&site=qq&menu=yes">
                            <i class="fa fa-qq fa-2x"></i></a>
                    
                </div>
            </nav>
        </div>
    </div>
</header>
      <div class="outer">
        <section id="main" class="body-wrap"><article id="post-record-blog" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-inner">
    
      <header class="article-header">
        
  
    <h1 class="post-title" itemprop="name">
      Android日常细节记录
    </h1>
    <div class="post-title-bar">
      <ul>
          
        <li>
          <i class="fa fa-calendar"></i>  2018-03-10
        </li>
        <li>
          <i class="fa fa-eye"></i>
          <span id="busuanzi_value_page_pv"></span>
        </li>
      </ul>
    </div>
  

          
      </header>
    
    <div class="article-entry post-content" itemprop="articleBody">
      
            
            <p>本人日常开发中总结一些细节记录。<br> <a id="more"></a></p>
<h2 id="1-JDK环境变量配置"><a href="#1-JDK环境变量配置" class="headerlink" title="1.JDK环境变量配置"></a>1.JDK环境变量配置</h2><p>JAVA_HOME=F:\Program Files\Java\jdk1.8.0_152</p>
<p>path=%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;</p>
<p>C:\ProgramData\Oracle\Java\javapath</p>
<p>classpath=,;%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar（注意：classpath要以.;开头英文状态下的“点  分号”）</p>
<h2 id="2-adb-android环境变量配置"><a href="#2-adb-android环境变量配置" class="headerlink" title="2.adb/android环境变量配置"></a>2.adb/android环境变量配置</h2><p>1.ANDROID_HOME法：能够类比JAVA_HOME法。</p>
<p>2.ANDROID_HOME=D:\adt-bundle\sdk</p>
<p>3.path=%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;</p>
<h2 id="3-开启Java1-8-能够使用lambda表达式"><a href="#3-开启Java1-8-能够使用lambda表达式" class="headerlink" title="3.开启Java1.8 能够使用lambda表达式"></a>3.开启Java1.8 能够使用lambda表达式</h2><h4 id="1是app-module-的话"><a href="#1是app-module-的话" class="headerlink" title="1是app module 的话"></a>1是app module 的话</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">  defaultConfig &#123;</div><div class="line">    //这个app</div><div class="line"> //为了开启Java8</div><div class="line">        jackOptions&#123;</div><div class="line">            enabled true;</div><div class="line">        &#125;</div><div class="line"></div><div class="line">&#125;</div><div class="line"></div><div class="line">    //开启Java1.8 能够使用lambda表达式</div><div class="line">    compileOptions&#123;</div><div class="line">        sourceCompatibility JavaVersion.VERSION_1_8</div><div class="line">        targetCompatibility JavaVersion.VERSION_1_8</div><div class="line">    &#125;</div></pre></td></tr></table></figure>
<h4 id="2是library-module-的话-则需引用一个插件。"><a href="#2是library-module-的话-则需引用一个插件。" class="headerlink" title="2是library module 的话 则需引用一个插件。"></a>2是library module 的话 则需引用一个插件。</h4><pre><code>在项目根目录gradle 
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">classpath &apos;me.tatarka:gradle-retrolambda:3.7.0&apos;</div></pre></td></tr></table></figure>
<h2 id="4-RecyclerView的GridView模式合并单元格"><a href="#4-RecyclerView的GridView模式合并单元格" class="headerlink" title="4.RecyclerView的GridView模式合并单元格"></a>4.RecyclerView的GridView模式合并单元格</h2><p>基本使用包含listview模式和GridView模式，最近使用GridView模式，<br>也就是使用GridLayoutManager 发现了一个有用的方法mLayoutManager.setSpanSizeLookup()，可以像word中表格合并单元格一样使用，合并掉一些单元格。  返回时占用列数<br>使用方法，在获取GridLayoutManager 以后调用一个方法<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup()</div><div class="line">	&#123;</div><div class="line">		@Override</div><div class="line">		public</div><div class="line">		int getSpanSize(final int position) &#123;</div><div class="line">			switch (mRecyclerViewAdapter.getItemViewType(position)) &#123;</div><div class="line">				case ContentModel.TYPE:</div><div class="line">					return 1;</div><div class="line">				case CategoryModel.TYPE:</div><div class="line">				default:</div><div class="line">					return 3;</div><div class="line">			&#125;</div><div class="line">		&#125;</div><div class="line">	&#125;);</div></pre></td></tr></table></figure></p>
<h2 id="5-实现toobar-返回返顶级按钮"><a href="#5-实现toobar-返回返顶级按钮" class="headerlink" title="5.实现toobar 返回返顶级按钮"></a>5.实现toobar 返回返顶级按钮</h2> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">&lt;activity android:name=&quot;.CheeseDetailActivity&quot;</div><div class="line">         android:parentActivityName=&quot;.MainActivity&quot;&gt;</div><div class="line">         &lt;meta-data android:name=&quot;android.support.PARENT_ACTIVITY&quot;</div><div class="line">             android:value=&quot;.MainActivity&quot; /&gt;</div><div class="line">     &lt;/activity&gt;</div></pre></td></tr></table></figure>
<h2 id="6-android-Sudio-移除无用依赖库"><a href="#6-android-Sudio-移除无用依赖库" class="headerlink" title="6. android Sudio 移除无用依赖库"></a>6. android Sudio 移除无用依赖库</h2> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"> android &#123;</div><div class="line">    configurations &#123;</div><div class="line">        all*.exclude group: &apos;com.android.support&apos;, module: &apos;support-annotations&apos;</div><div class="line">        all*.exclude group: &apos;com.android.support&apos;, module: &apos;support-compat&apos;</div><div class="line">    &#125;</div><div class="line">    compile(&apos;com.android.support:appcompat-v7:25.1.1&apos;, &#123;</div><div class="line">        exclude group: &apos;com.android.support&apos;, module: &apos;appcompat-v7&apos;</div><div class="line">    &#125;)</div><div class="line">    compile(&apos;com.android.support:support-v4:25.1.1&apos;, &#123;</div><div class="line">        exclude group: &apos;com.android.support&apos;, module: &apos;support-v4&apos;</div><div class="line">    &#125;)</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="7-android-Sudio-版本统一管理"><a href="#7-android-Sudio-版本统一管理" class="headerlink" title="7. android Sudio 版本统一管理"></a>7. android Sudio 版本统一管理</h2> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">allprojects &#123;</div><div class="line"> repositories &#123;</div><div class="line">       jcenter()</div><div class="line">       maven &#123; url &quot;https://dl.bintray.com/thelasterstar/maven/&quot; &#125;</div><div class="line">       maven &#123; url &quot;https://jitpack.io&quot; &#125;</div><div class="line"></div><div class="line">   &#125;</div><div class="line">   project.ext &#123;</div><div class="line">       compileSdkVersion=25</div><div class="line">       targetSdkVersion=25</div><div class="line">       buildToolsVersion=&apos;25.0.3&apos;</div><div class="line">       minSdkVersion=14</div><div class="line">       supportVersion = &quot;25.3.1&quot;</div><div class="line">   &#125;</div><div class="line">   tasks.withType(Javadoc) &#123;</div><div class="line">       options &#123;</div><div class="line">           encoding &quot;UTF-8&quot;</div><div class="line">           charSet &apos;UTF-8&apos;</div><div class="line">           links &quot;http://docs.oracle.com/javase/7/docs/api&quot;</div><div class="line">       &#125;</div><div class="line">   &#125;</div><div class="line">   &#125;</div></pre></td></tr></table></figure>
<p> 使用示例：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">android &#123;</div><div class="line">   compileSdkVersion project.ext.compileSdkVersion</div><div class="line">   buildToolsVersion project.ext.buildToolsVersion</div><div class="line">   defaultConfig &#123;</div><div class="line"></div><div class="line">       minSdkVersion project.ext.minSdkVersion</div><div class="line">       targetSdkVersion project.ext.targetSdkVersion</div><div class="line">       versionCode project.ext.versionCode</div><div class="line">       versionName project.ext.versionName</div><div class="line">       multiDexEnabled true</div><div class="line">       &#125;</div></pre></td></tr></table></figure></p>
<h2 id="8-android-studio-如何提示方法的用法"><a href="#8-android-studio-如何提示方法的用法" class="headerlink" title="8.android studio 如何提示方法的用法"></a>8.android studio 如何提示方法的用法</h2><p>  Android Studio也可以设置的。 Preferences &gt; Editor &gt;Generan&gt; Show doc on mouse move:勾选上</p>
<h2 id="9-svg-4-4-以下版本使用"><a href="#9-svg-4-4-以下版本使用" class="headerlink" title="9. svg 4.4 以下版本使用"></a>9. svg 4.4 以下版本使用</h2><p> 4.4 以下版本 TextView drawableTOp 等 不能用svg<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">defaultConfig &#123;</div><div class="line"> vectorDrawables.useSupportLibrary = true</div><div class="line"> &#125;</div></pre></td></tr></table></figure></p>
<h2 id="10-项目新增图片后保存本地，读取相册没有更新解决方法"><a href="#10-项目新增图片后保存本地，读取相册没有更新解决方法" class="headerlink" title="10.项目新增图片后保存本地，读取相册没有更新解决方法"></a>10.项目新增图片后保存本地，读取相册没有更新解决方法</h2><p>  新增图片后，发送该广播i通知系统更新相册<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(path))));</div></pre></td></tr></table></figure></p>
<h2 id="11-gridView-item-Button-点击冲突事件"><a href="#11-gridView-item-Button-点击冲突事件" class="headerlink" title="11. gridView item Button 点击冲突事件"></a>11. gridView item Button 点击冲突事件</h2><p> item 根布局属性<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">android:descendantFocusability=”blocksDescendants”</div></pre></td></tr></table></figure></p>
<p>  点击控件<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">android:focusable=&quot;false&quot;    </div><div class="line">android:checked=&quot;false&quot;</div><div class="line">android:clickable=&quot;false&quot;</div><div class="line">android:focusable=&quot;false&quot;</div><div class="line">android:focusableInTouchMode=&quot;false&quot;</div></pre></td></tr></table></figure></p>
<h2 id="11-多屏幕适配"><a href="#11-多屏幕适配" class="headerlink" title="11.多屏幕适配"></a>11.多屏幕适配</h2>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</div><div class="line">     &lt;supports-screens</div><div class="line">      android:anyDensity=&quot;true&quot;</div><div class="line">      android:largeScreens=&quot;true&quot;</div><div class="line">      android:normalScreens=&quot;true&quot;</div><div class="line">      android:resizeable=&quot;true&quot;</div><div class="line">      android:smallScreens=&quot;true&quot; /&gt;</div><div class="line">      &lt;/manifest&gt;</div></pre></td></tr></table></figure>
<h2 id="12-解决系统改变字体大小的时候导致的界面布局混乱的问题"><a href="#12-解决系统改变字体大小的时候导致的界面布局混乱的问题" class="headerlink" title="12.解决系统改变字体大小的时候导致的界面布局混乱的问题"></a>12.解决系统改变字体大小的时候导致的界面布局混乱的问题</h2><p>  从android4.0起系统设置的”显示“提供设置字体大小的选项。这个设置直接会影响到所有sp为单位的字体适配，所以很多app在设置了系统字体后瞬间变得面目全非。下面是解决方案</p>
<p>  例如：Contacts中需要在com.android.contacts.activities.TransactionSafeActivity加入以下code<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">  @Override</div><div class="line">public Resources getResources() &#123;</div><div class="line">    Resources res = super.getResources();  </div><div class="line">    Configuration config=new Configuration();  </div><div class="line">    config.setToDefaults();  </div><div class="line">    res.updateConfiguration(config,res.getDisplayMetrics() );</div><div class="line">    return res;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>  如果app中只是个别界面不需要，可改造下此方法<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">@Override</div><div class="line"> public Resources getResources() &#123;</div><div class="line">     if(isNeedSystemResConfig())&#123;</div><div class="line">         return super.getResources();</div><div class="line">     &#125;else&#123;</div><div class="line">         Resources res = super.getResources();  </div><div class="line">         Configuration config=new Configuration(); </div><div class="line">         config.setToDefaults(); </div><div class="line">         res.updateConfiguration(config,res.getDisplayMetrics() );</div><div class="line">         return res;</div><div class="line">     &#125;</div><div class="line"> &#125;</div><div class="line">    // 默认返回true，使用系统资源，如果个别界面不需要，在这些activity中Override this method ，then return false;</div><div class="line"> protected boolean isNeedSystemResConfig() &#123;</div><div class="line">     return true;</div><div class="line"> &#125;</div></pre></td></tr></table></figure></p>
<h2 id="13-华为-手机-调试-LOCAT-日志不输出问题"><a href="#13-华为-手机-调试-LOCAT-日志不输出问题" class="headerlink" title="13.华为 手机 调试 LOCAT 日志不输出问题"></a>13.华为 手机 调试 LOCAT 日志不输出问题</h2><p>  用手机进行调试，在电脑上不显示logcat信息。<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">  在拨打电话界面，录入*#*#2846579#*#* </div><div class="line"> 自动进入开发界面菜单，按以下步骤:</div><div class="line"></div><div class="line">ProjectMenu -&gt; Background setting -&gt; Log Setting   选择打开即可.</div></pre></td></tr></table></figure></p>
<h2 id="14-RecyclerView嵌套在ScrollView中显示不全"><a href="#14-RecyclerView嵌套在ScrollView中显示不全" class="headerlink" title="14.RecyclerView嵌套在ScrollView中显示不全"></a>14.RecyclerView嵌套在ScrollView中显示不全</h2><p>  Android 6.0+ RecyclerView嵌套在ScrollView中显示不全<br>终极解决方案<br>终极解决办法是在RecyclerView的外部套上一层RelativeLayout<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">&lt;RelativeLayout</div><div class="line">    android:layout_width=&quot;match_parent&quot;</div><div class="line">    android:layout_height=&quot;wrap_content&quot;</div><div class="line">    android:descendantFocusability=&quot;blocksDescendants&quot;&gt;</div><div class="line"></div><div class="line">        &lt;android.support.v7.widget.RecyclerView</div><div class="line">            android:id=&quot;@+id/menuRv&quot;</div><div class="line">            android:layout_width=&quot;match_parent&quot;</div><div class="line">            android:layout_height=&quot;wrap_content&quot;</div><div class="line">            android:layout_marginLeft=&quot;@dimen/margin_16&quot;</div><div class="line">            android:layout_marginRight=&quot;@dimen/margin_16&quot;/&gt;</div><div class="line"></div><div class="line">&lt;/RelativeLayout&gt;</div></pre></td></tr></table></figure></p>
<p>发现RecyclerView完全显示出来了，完美解决！</p>
<h2 id="15-PopUpWindow-防止导航栏显示"><a href="#15-PopUpWindow-防止导航栏显示" class="headerlink" title="15.PopUpWindow 防止导航栏显示"></a>15.PopUpWindow 防止导航栏显示</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pw.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);</div></pre></td></tr></table></figure>
<h2 id="16-list数快速倒叙"><a href="#16-list数快速倒叙" class="headerlink" title="16.  list数快速倒叙"></a>16.  list数快速倒叙</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Collections.reverse()</div></pre></td></tr></table></figure>
<h2 id="17-kotlin-自定义listener-用法"><a href="#17-kotlin-自定义listener-用法" class="headerlink" title="17.kotlin 自定义listener 用法"></a>17.kotlin 自定义listener 用法</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">class Test &#123;</div><div class="line"></div><div class="line">    private   var  onActionListenerListener: ((String) -&gt; Unit)? = null</div><div class="line"></div><div class="line">    fun  setList(  onActionListenerListener: (String) -&gt; Unit)&#123;</div><div class="line">      this.onActionListenerListener=onActionListenerListener</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    fun  onClick()&#123;</div><div class="line">        onActionListenerListener?.invoke(&quot;测试回调函数&quot;)</div><div class="line"></div><div class="line">    &#125;</div><div class="line">    &#125;</div></pre></td></tr></table></figure>
<p>更多总结敬请期待</p>

            <div class="post-copyright">
    <div class="content">
        <p>最后更新： 2018年03月10日 19:32</p>
        <p>原始链接： <a class="post-url" href="/2018/03/10/record-blog/" title="Android日常细节记录">http://yangchaojiang.cn/2018/03/10/record-blog/</a></p>
        <footer>
            <a href="http://yangchaojiang.cn">
                <img src="/images/logo.png" alt="杨朝江">
                杨朝江
            </a>
        </footer>
    </div>
</div>

      
    </div>
    <footer class="article-footer">
        
        
<div class="post-share">
    <a href="javascript:;" id="share-sub" class="post-share-fab">
        <i class="fa fa-share-alt"></i>
    </a>
    <div class="post-share-list" id="share-list">
        <ul class="share-icons">
          <li>
            <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yangchaojiang.cn/2018/03/10/record-blog/&title=《Android日常细节记录》 — yangchaojiang&pic=http://yangchaojiang.cnimages/logo.png" data-title="微博">
              <i class="fa fa-weibo"></i>
            </a>
          </li>
          <li>
            <a class="weixin share-sns" id="wxFab" href="javascript:;" data-title="微信">
              <i class="fa fa-weixin"></i>
            </a>
          </li>
          <li>
            <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yangchaojiang.cn/2018/03/10/record-blog/&title=《Android日常细节记录》 — yangchaojiang&source=本人日常开发中总结一些细节记录。" data-title="QQ">
              <i class="fa fa-qq"></i>
            </a>
          </li>
          <li>
            <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yangchaojiang.cn/2018/03/10/record-blog/" data-title="Facebook">
              <i class="fa fa-facebook"></i>
            </a>
          </li>
          <li>
            <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《Android日常细节记录》 — yangchaojiang&url=http://yangchaojiang.cn/2018/03/10/record-blog/&via=http://yangchaojiang.cn" data-title="Twitter">
              <i class="fa fa-twitter"></i>
            </a>
          </li>
          <li>
            <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yangchaojiang.cn/2018/03/10/record-blog/" data-title="Google+">
              <i class="fa fa-google-plus"></i>
            </a>
          </li>
        </ul>
     </div>
</div>
<div class="post-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;" id="wxShare-close">×</a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=http://yangchaojiang.cn/2018/03/10/record-blog/" alt="微信分享二维码">
</div>

<div class="mask"></div>

        
        <ul class="article-footer-menu">
            
            
  <li class="article-footer-tags">
    <i class="fa fa-tags"></i>
      
    <a href="/tags/Android/" class="color3">Android</a>
      
    <a href="/tags/Kotlin/" class="color2">Kotlin</a>
      
    <a href="/tags/java/" class="color5">java</a>
      
  </li>

        </ul>
        
    </footer>
  </div>
</article>


    <aside class="post-toc-pos post-toc-top" id="post-toc">
        <nav class="post-toc-wrap">
            <ol class="post-toc"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#1-JDK环境变量配置"><span class="post-toc-text">1.JDK环境变量配置</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#2-adb-android环境变量配置"><span class="post-toc-text">2.adb/android环境变量配置</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#3-开启Java1-8-能够使用lambda表达式"><span class="post-toc-text">3.开启Java1.8 能够使用lambda表达式</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#1是app-module-的话"><span class="post-toc-text">1是app module 的话</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#2是library-module-的话-则需引用一个插件。"><span class="post-toc-text">2是library module 的话 则需引用一个插件。</span></a></li></ol></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#4-RecyclerView的GridView模式合并单元格"><span class="post-toc-text">4.RecyclerView的GridView模式合并单元格</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#5-实现toobar-返回返顶级按钮"><span class="post-toc-text">5.实现toobar 返回返顶级按钮</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#6-android-Sudio-移除无用依赖库"><span class="post-toc-text">6. android Sudio 移除无用依赖库</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#7-android-Sudio-版本统一管理"><span class="post-toc-text">7. android Sudio 版本统一管理</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#8-android-studio-如何提示方法的用法"><span class="post-toc-text">8.android studio 如何提示方法的用法</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#9-svg-4-4-以下版本使用"><span class="post-toc-text">9. svg 4.4 以下版本使用</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#10-项目新增图片后保存本地，读取相册没有更新解决方法"><span class="post-toc-text">10.项目新增图片后保存本地，读取相册没有更新解决方法</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#11-gridView-item-Button-点击冲突事件"><span class="post-toc-text">11. gridView item Button 点击冲突事件</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#11-多屏幕适配"><span class="post-toc-text">11.多屏幕适配</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#12-解决系统改变字体大小的时候导致的界面布局混乱的问题"><span class="post-toc-text">12.解决系统改变字体大小的时候导致的界面布局混乱的问题</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#13-华为-手机-调试-LOCAT-日志不输出问题"><span class="post-toc-text">13.华为 手机 调试 LOCAT 日志不输出问题</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#14-RecyclerView嵌套在ScrollView中显示不全"><span class="post-toc-text">14.RecyclerView嵌套在ScrollView中显示不全</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#15-PopUpWindow-防止导航栏显示"><span class="post-toc-text">15.PopUpWindow 防止导航栏显示</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#16-list数快速倒叙"><span class="post-toc-text">16.  list数快速倒叙</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#17-kotlin-自定义listener-用法"><span class="post-toc-text">17.kotlin 自定义listener 用法</span></a></li></ol>
        </nav>
    </aside>
    

<nav id="article-nav">
  
  
    <a href="/2018/03/06/lambda-blog/" id="article-nav-older" class="article-nav-link-wrap">
      <span class="article-nav-title">Lambda 表达式有何用处？如何使用？（非原创）</span>
      <i class="fa fa-hand-o-right" aria-hidden="true"></i>
    </a>
  
</nav>



    
        <div id="SOHUCS" sid="record-blog" ></div>
<script type="text/javascript">
    (function(){
        var appid = 'cyt36tWXs';
        var conf = '42b79e0329709ef48318d7d6739122c2';
        var width = window.innerWidth || document.documentElement.clientWidth;
        if (width < 960) {
            window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})}); } })(); </script>
    
</section>
        
      </div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info" class="inner">
      
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


      <p>
        Powered by  <a href="http://hexo.io/" target="_blank">Hexo</a>
        Theme <a href="//github.com/wongminho/hexo-theme-miho" target="_blank">MiHo</a>
      &copy; 2018 杨朝江<br>
      </p>
    </div>
  </div>
</footer>
    <script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
  var mihoConfig = {
      root: "http://yangchaojiang.cn",
      animate: true,
      isHome: false,
      share: true
  }
</script>
<div class="sidebar">
    <div id="sidebar-search" title="Search">
        <i class="fa fa-search"></i>
    </div>
    <div id="sidebar-category" title="Categories">
        <i class="fa fa-book"></i>
    </div>
    <div id="sidebar-tag" title="Tags">
        <i class="fa fa-tags"></i>
    </div>
    <div id="sidebar-top">
        <span class="sidebar-top-icon"><i class="fa fa-angle-up"></i></span>
    </div>
</div>
<div class="sidebar-menu-box" id="sidebar-menu-box">
    <div class="sidebar-menu-box-container">
        <div id="sidebar-menu-box-categories">
            
        </div>
        <div id="sidebar-menu-box-tags">
            <a href="/tags/Android-Kotlin/" style="font-size: 10px;">-Android -Kotlin</a> <a href="/tags/Android/" style="font-size: 20px;">Android</a> <a href="/tags/Architecture-Components/" style="font-size: 10px;">Architecture Components</a> <a href="/tags/Architecture-Components/" style="font-size: 13.33px;">Architecture_Components</a> <a href="/tags/Gradle/" style="font-size: 10px;">Gradle</a> <a href="/tags/Kotlin/" style="font-size: 16.67px;">Kotlin</a> <a href="/tags/LiveData/" style="font-size: 10px;">LiveData</a> <a href="/tags/Room/" style="font-size: 10px;">Room</a> <a href="/tags/java/" style="font-size: 13.33px;">java</a> <a href="/tags/kotlin/" style="font-size: 10px;">kotlin</a> <a href="/tags/lambda/" style="font-size: 10px;">lambda</a> <a href="/tags/leficycle/" style="font-size: 10px;">leficycle</a>
        </div>
    </div>
    <a href="javascript:;" class="sidebar-menu-box-close">&times;</a>
</div>
<div class="mobile-header-menu-nav" id="mobile-header-menu-nav">
    <div id="mobile-header-menu-container">
        <span class="title">Menu</span>
        <ul class="mobile-header-menu-navbar">
            
            <li>
                <a target="_blank" href="//yanganan.cn">
                    <i class="fa fa-home"></i><span>Home</span>
                </a>
            </li>
            
            <li>
                <a  href="/archives">
                    <i class="fa fa-archive"></i><span>Archives</span>
                </a>
            </li>
            
            <li>
                <a target="_blank" href="http://www.yanganan.cn/server/about/aboutme.html">
                    <i class="fa fa-user"></i><span>About</span>
                </a>
            </li>
            
        </ul>
    </div>
</div>
<div class="search-wrap">
    <span class="search-close">&times;</span>
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
            <i class="icon icon-lg icon-chevron-left"></i>
        </a>
        <input class="search-field" placeholder="Search..." id="keywords">
        <a id="search-submit" href="javascript:;">
            <i class="fa fa-search"></i>
        </a>
    <div class="search-container" id="search-container">
        <ul class="search-result" id="search-result">
        </ul>
    </div>
</div>

<div id="search-tpl">
    <li class="search-result-item">
        <a href="{url}" class="search-item-li">
            <span class="search-item-li-title" title="{title}">{title}</span>
        </a>
    </li>
</div>
<script src="/js/search.js"></script>
<script src="/js/main.js"></script>


  <script src="//cdn.bootcss.com/particles.js/2.0.0/particles.min.js"></script>
  <div id="particles"></div>
  <script src="/js/particles.js"></script>







  <link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.5.0/animate.min.css">
  <script src="//cdn.bootcss.com/scrollReveal.js/3.0.5/scrollreveal.js"></script>
  <script src="/js/animate.js"></script>

  </div>
</body>
</html>